package com.by.service.impl;

import com.by.bean.Leave;
import com.by.bean.PageBean;
import com.by.mapper.OaApproveMapper;
import com.by.mapper.OaLeaveMapper;
import com.by.mapper.OaReciverMapper;
import com.by.service.OaLeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
public class OaLeaveServerImpl implements OaLeaveService {
    @Autowired
    OaLeaveMapper leaveMapper;
    @Autowired
    OaApproveMapper approveMapper;
    @Autowired
    OaReciverMapper reciverMapper;
    @Transactional//声明需要事务管理
    @Override
    public int save(Leave leave) {
        int rs= leaveMapper.save(leave);
        if(rs>0){
            //保存审批人
            rs=approveMapper.save(leave.getId(),leave.getApproveList());
            //保存接收人
            rs= reciverMapper.save(leave.getId(),leave.getReciverList());
        }
        return 1;
    }

    @Override
    public PageBean query(Map map) {
        //默认值
        int page=1;
        int pageSize=10;
        //判断用户是否传递page
        if(map.containsKey("page")){
            page=Integer.parseInt(map.get("page").toString());
        }
        //判断用户是否传递pageSize
        if(map.containsKey("pageSize")){
            pageSize=Integer.parseInt(map.get("pageSize").toString());
        }
        //执行分页方法

        return null;
    }
}
